#include <iostream>
#include <iomanip>
#include <string>
#include <clocale>
#include <chrono>
#include "Watch.h"

using namespace std;
using namespace Course;
//using namespace Course::adt;

#pragma optimize("",off)
//Rekursiv funktion

int recursive_faculty(int n)
{
	if(n <= 1)
		return 1;
	else
	{
		return n * recursive_faculty(n-1);	
	}
}

//Iterativ funktion
int iterative_faculty(int n)
{
	int product = 1;
	if(n==0)
		return 1;

	/*for(int i=1; i<=n ; i++)
	{
	product = product * i;
	}*/

	for(int i=0; i<n ; i++)
	{
		product = product * (i+1);
	}

	return product;
}



int main()
{
	setlocale (LC_ALL, "swedish");

	Watch w;
	Course::microseconds t0;
	Course::microseconds t1;
	Course::microseconds t;
	
	w.restart();
	//Tom loop
	for (int j = 0; j < 10000; j++)
	{
		;
	}
	t=w.elapsedUs();

	w.restart();
	//Rekursivt
	for (int j = 1; j < 10000; j++)
	{
		recursive_faculty(j);
		
	}
	t0=w.elapsedUs();
	cout << setprecision(9) << (t0.count()-t.count()) /10000.0<< " micro-sec" << endl;

	//cout << endl;

	w.restart();
	//Iterativt
	for (int j = 1; j < 10000; j++)
	{
		
			iterative_faculty(j);
		
	}
	t1=w.elapsedUs();
	cout << setprecision(9) << (t1.count()-t.count()) /10000.0<< " micro-sec" << endl;


	cout << endl;
	system("PAUSE");
	return 0;
}

#pragma optimize("",on)